
import { ref } from 'vue'
const useForm = (submitCallback?: (d: any) => void) => {
    // 表单实例
    const CustomeFormRef = ref()
    // 控制表单多次提交
    const loading = ref(false)
    // 数据回显
    const displayData = (data: any) => {
        CustomeFormRef.value.displayData(data)
    }
    // 重置表单数据
    const resetForm = () => {
        CustomeFormRef.value.resetForm()
    }
    // 验证表单数据(通过实例获取)
    const validateForm = (callback?: (data: unknown) => void): Promise<boolean> => {
        return CustomeFormRef.value.validateForm(callback)
    }
    // 获取表单数据
    const getFormData = () => {
        return CustomeFormRef.value.getFormData()
    }
    // 表格提交回调事件
    const submit = (data: any) => {
        if (submitCallback) submitCallback(data)
    }
    return {
        CustomeFormRef,
        displayData,
        submit,
        loading,
        validateForm,
        getFormData,
        resetForm
    }

}

export default useForm